<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>

<%
	
	String id = request.getParameter("id");
	String oldId = "";
	Cookie[] arr = request.getCookies();
	
	if (arr != null) {
		for (Cookie c : arr) {
			if ("goodId".equals(c.getName())) {
				 oldId = c.getValue()+",";
			}
		}
	}
	// 字符串拼接
	oldId += id;
	
	System.out.println(oldId+" addToCat");
	
	Cookie cookie = new Cookie("goodId",oldId);
	
	// 设置cookie的生存时间
	cookie.setMaxAge(30*60);
	// 把数据给客户端(响应)
	response.addCookie(cookie);

%>

<body>
<a href="showCart.jsp">显示购物车</a>

</body>
</html>